import 'package:flutter/material.dart';
import '../../resources/resources.dart';
import '../my_text.dart';

class MyPopMenuItem extends StatefulWidget {
  final String title;
  final Widget? icon;
  final Widget? leading;
  final Color? fontColor;
  final double? fontSize;
  final FontWeight? fontWeight;
  bool isDivider;
  final bool visible;
  final bool? selected;

  final VoidCallback? onTap;

  static const double menuItemHeight = 44;
  static const double menuItemWidth = 250;

  MyPopMenuItem({
    super.key,
    required this.title,
    this.onTap,
    this.icon,
    this.fontColor,
    this.fontSize,
    this.isDivider = true,
    this.visible = true,
    this.leading,
    this.selected,
    this.fontWeight,
  });

  @override
  State<MyPopMenuItem> createState() => _MyPopMenuItemState();
}

class _MyPopMenuItemState extends State<MyPopMenuItem> {
  bool hover = false;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: widget.onTap,
      onHover: (hover) {
        setState(() {
          this.hover = hover;
        });
      },
      child: Container(
        height: MyPopMenuItem.menuItemHeight,
        width: MyPopMenuItem.menuItemWidth,
        decoration: BoxDecoration(
          border: widget.isDivider
              ? const Border(
                  bottom: BorderSide(
                    color: Color(0xffb5b5b8),
                    width: 0.3,
                  ),
                )
              : null,
        ),
        padding: const EdgeInsets.only(left: 0, right: 20, top: 0, bottom: 0),
        child: Row(
          children: [
            widget.leading ??
                (widget.selected == null
                    ? const SizedBox(
                        width: 20,
                      )
                    : widget.selected!
                        ? const Padding(
                            padding: EdgeInsets.only(left: 8, right: 6),
                            child: Icon(
                              CupIcons.checkmark_circle,
                              size: 20,
                              color: defaultColor,
                            ),
                          )
                        : const SizedBox(
                            width: 34,
                          )),
            Expanded(
              child: MyText(
                widget.title,
                size: widget.fontSize ?? 17,
                textAlign: TextAlign.start,
                color: widget.fontColor,
                weight: widget.fontWeight,
              ),
            ),
            gaph8,
            widget.icon ?? const SizedBox.shrink(),
          ],
        ),
      ),
    );
  }
}
